package com.itfreer.data.metadata;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 定义数据注册服务接口
 */
@RestController
@RequestMapping("/metadata")
@Api("元数据服务")
public class RestMetadataRegService {

	@Autowired(required = false)
	private MetadataRegService service;

	protected MetadataRegService getService() {
		return service;
	}

	/**
	 * 将表的元数据注册到元数据结构中
	 * 
	 * @param tableName
	 *            表名称
	 * @param mid
	 *            元数据ID
	 * @throws Exception
	 */
	@ApiOperation(value = "元数据注册")
	@ApiImplicitParams(value = { @ApiImplicitParam(name = "tn", value = "需要注册的表", paramType = "path", required = true),
			@ApiImplicitParam(name = "mid", value = "元数据ID", paramType = "path", required = true) })
	@PostMapping(value = "/reg/{tn:.+}/{mid:.+}", produces = "application/json")
	public void reg(@PathVariable("tn") String tableName, @PathVariable("mid") String mid) throws Exception {
		getService().reg(tableName, mid);
	}

	/**
	 * 代码生成
	 */
	@ApiOperation(value = "元数据注册")
	@ApiImplicitParams(value = {
			@ApiImplicitParam(name = "para", value = "注册参数", paramType = "body", required = true) })
	@PostMapping(value = "/reg2", produces = "application/json")
	public void simple(HttpServletResponse response, @RequestBody MetadataRegPara para) throws Exception {
		getService().reg(para);
	}
}
